package cn.iocoder.yudao.module.book.dal.mysql.bookshelf;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.book.controller.app.bookcase.vo.AppBooksRespVO;
import cn.iocoder.yudao.module.book.controller.app.bookcase.vo.AppBookshelfRespVO;
import cn.iocoder.yudao.module.book.controller.app.booksShell.vo.AppCollectionsRespVO;
import cn.iocoder.yudao.module.book.controller.app.category.vo.AppzdyReqVO;
import cn.iocoder.yudao.module.book.dal.dataobject.bookshelf.BookshelfDO;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.book.controller.admin.bookshelf.vo.*;
import org.apache.ibatis.annotations.Param;

import javax.validation.Valid;

/**
 * 书架 Mapper
 *
 * @author xi
 */
@Mapper
public interface BookshelfMapper extends BaseMapperX<BookshelfDO> {

    default PageResult<BookshelfDO> selectPage(BookshelfPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BookshelfDO>()
                .eqIfPresent(BookshelfDO::getBookshelfId, reqVO.getBookshelfId())
                .eqIfPresent(BookshelfDO::getUserId, reqVO.getUserId())
                .eqIfPresent(BookshelfDO::getCollectionId, reqVO.getCollectionId())
                .eqIfPresent(BookshelfDO::getCategoryId, reqVO.getCategoryId())
                .betweenIfPresent(BookshelfDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BookshelfDO::getBookshelfId));
    }

    List<AppBookshelfRespVO> getAll(@Param("userId") Integer userId);

    int deletes(@Param("userId") Long userId, @Param("collectionId") Integer collectionId);

    List<AppBooksRespVO> getByCollectionId(@Param("id") Integer id);

//    int deleteByBookId(Long userId, Integer id);

//    int deleteByCollectionId(@Param("userId") Long userId, @Param("id") Integer id);

    int markGroupTop(@Param("userId") Long userId, @Param("id") Integer id);

    Boolean addBook(@Param("bookId") Integer bookId,@Param("collectionId") Integer collectionId,@Param("userId") Integer userId,@Param("time") String time);

    List<AppBookshelfRespVO> selectByUserId(@Param("userId") Long userId);

    List<BookshelfDO> selectByCategoryId(@Param("userId") Long userId,@Param("categoryId") Integer categoryId);

    List<AppzdyReqVO> selectAllByCategoryIdAndClassifyId(@Param("categoryId") Integer id, @Param("classifyId") Integer classifyId);

    List<AppCollectionsRespVO> selectAllByCategoryId(@Param("categoryId") Integer categoryId);

    List<AppCollectionsRespVO> selectAllCollectionsByClassfiId(Integer id);

    List<AppBooksRespVO> getdraftByCollectionId(@Param("setId") Integer setId);

    /**
     * 恢复书架中的集合记录（将 deleted 设置为 0）
     */
    int restoreByCollectionId(@Param("userId") Long userId, @Param("collectionId") Integer collectionId);

    /**
     * 恢复书架中的书本记录（将 deleted 设置为 0）
     */
    int restoreByBookId(@Param("userId") Long userId, @Param("bookId") Integer bookId);
}